package com.pawernode.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
@Slf4j
public class MessageService {
    @Resource
    private RabbitTemplate rabbitTemplate;

    public void sendMsg() {
        // 使用建造者模式创建消息对象
        Message message = MessageBuilder.withBody("hello rabbitmq".getBytes()).build();
        // 参数1：交换机名，参数2：路由键，参数3：消息对象
        rabbitTemplate.convertAndSend("exchange-direct", "info",message);
        log.info("消息发送完毕，发送时间为：{}",new Date());
    }
}
